import {
  fileURLToPath,
  URL
} from 'node:url'

import {
  defineConfig
} from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {
  NaiveUiResolver
} from 'unplugin-vue-components/resolvers'
// import { createVuePlugin as VitePluginLess } from 'vite-plugin-less'

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    proxy: {
      '/api': {
        // target: 'http://mes-rfg-dev.meicloud.com:6688',
        // target: 'http://172.16.40.235', // 生产环境-服务器1
        // target: 'http://172.16.40.236', // 生产环境-服务器2
        target: 'http://172.17.193.236:6677',
        // changeOrigin: true,
        // rewrite: path => {
        //   return path.replace('/api', '')
        // }
      }
    }
  },
  plugins: [
    vue(),
    vueJsx(),
    vueDevTools(),
    AutoImport({
      include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/],
      // dts: true,
      // 自动导入 Vue 相关函数，如：ref, reactive, toRef 等
      imports: [
        'vue',
        'vue-router',
        'pinia',
        // {
        //   'naive-ui': ['useDialog', 'useMessage', 'useNotification', 'useLoadingBar']
        // }
      ],
      // dts: './auto-imports.d.ts', // 此处引入自动生成的声明文件
      eslintrc: {
        enabled: false // 1、true时生成eslint配置文件，2、生成后改为false，避免重复消耗
      }
    }),
    Components({
      resolvers: [NaiveUiResolver()]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src',
        import.meta.url))
    }
  }
})

/**
 * 文献：
 * Vue3+Vite4+Naive-UI 项目自动导入API和组件
 *      https://developer.aliyun.com/article/1130566
 *
 *
 */